home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.input;
-
- import sub_arctic.lib.manager;
- import sub_arctic.lib.sub_arctic_error;
-
- import java.util.Vector;
-
- /**
- * Abstract base class for all input policies. An input policy is an object
- * which uses a set of agents to deliver an event according to a particular
- * policy (such as the positional policy that delivers events based on their
- * position). This class provides the basic API along with implementation
- * of an agent list and related manipulation methods.
- *
- * @author Scott Hudson
- */
- public abstract class input_policy {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Simple constructor */
- public input_policy()
- {
- _agent_list = new Vector();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** The agent list for this policy. This contains dispatch_agent objects. */
- protected Vector _agent_list;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** The number of agents in the policies agent list. */
- public int num_agents() {return _agent_list.size();}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Return the agent at a given index in the agent list.
- * @param int indx the index of the agent we want.
- * @returns dispatch_agent the agent at that position.
- */
- public dispatch_agent agent(int indx)
- {
- /* bounds check */
- if (indx < 0 || indx >= num_agents())
- throw new sub_arctic_error("Agent index out of bounds");
-
- /* pull out the agent */
- return (dispatch_agent)_agent_list.elementAt(indx);
- }
-
- //had:
- //* @exception index_bounds if the index given is out of range.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Add an agent to the agent list after the one given. If after is coded
- * as null, then the agent is placed at the end of the agent list.
- *
- * @param dispatch_agent add the agent to add to the list.
- * @param dispatch_agent after the agent to place it after (or null to
- * indicate that it should go at the end of the
- * list).
- */
- public void add_agent_after(dispatch_agent add, dispatch_agent after)
- {
- /* if we have nothing to go after put it at the end */
- if (after == null)
- _agent_list.addElement(add);
- else
- {
- int indx = _agent_list.indexOf(after);
- if (indx < 0)
- throw new sub_arctic_error(
- "Attempt to install dispatch agent after uninstalled agent");
- else
- /* put it right after the one given */
- _agent_list.insertElementAt(add,indx+1);
- }
- }
-
- //had:
- //* @exception bad_value if the after agent is not in the list.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Add an agent to the agent list before the one given. If before is coded
- * as null, then the agent is placed at the beginning of the agent list.
- *
- * @param dispatch_agent add the agent to add to the list.
- * @param dispatch_agent after the agent to place it before (or null to
- * indicate that it should go at the beginning
- * of the list).
- */
- public void add_agent_before(dispatch_agent add, dispatch_agent before)
- {
- /* if we have nothing to go before put it at the beginning */
- if (before == null)
- _agent_list.insertElementAt(add,0);
- else
- {
- int indx = _agent_list.indexOf(before);
- if (indx < 0)
- throw new sub_arctic_error(
- "Attempt to install dispatch agent before uninstalled agent");
- else
- /* put it right before the one given */
- _agent_list.insertElementAt(add,indx);
- }
- }
-
- //had:
- //* @exception bad_value if the before agent is not in the list.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Attempt to dispatch an event under this policy.
- * @param event evt the event to dispatch.
- * @return boolean indicating whether the event was dispatched and consumed.
- */
- public abstract boolean dispatch_event(event evt);
- //
- // typical implementation might look something like:
- //
- // {
- // dispatch_agent an_agent;
- //
- // /* walk down the agent list */
- // for (int i = 0; i < num_agents(); i++)
- // {
- // /* try to dispatch with the agent. if it takes it, we are done */
- // an_agent = (dispatch_agent)_agent_list.elementAt(i);
- // if (an_agent.event_is_useful(evt) &&
- // an_agent.dispatch_event(evt, ??, ??, manager.event_seq_num()))
- // return true;
- // }
- //
- // /* nobody wanted it */
- // return false;
- // }
-
- //had:
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- };
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-